home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / cxref-1.001 / cxref-1~ / cxref / cxref.el < prev    next >
Encoding:
Text File  |  1996-02-24  |  5.7 KB  |  192 lines

  1. ;; $Header: /home/amb/cxref/RCS/cxref.el 1.4 1996/02/24 14:52:56 amb Exp $
  2. ;;
  3. ;; C Cross Referencing & Documentation tool. Version 1.0
  4. ;;
  5. ;; Some useful Emacs lisp functions for use with cxref.
  6. ;; Adds in comments of the appropriate format for cxref.
  7. ;;
  8. ;; Written by Andrew M. Bishop
  9. ;;
  10. ;; This file Copyright 1995,96 Andrew M. Bishop
  11. ;; It may be distributed under the GNU Public License, version 2, or
  12. ;; any higher version.  See section COPYING of the GNU Public license
  13. ;; for conditions under which this file may be redistributed.
  14. ;;
  15.  
  16. (define-key c-mode-map "\C-c\C-f"  'cxref-file-comment)     ;; Control-C Control-F
  17. (define-key c-mode-map "\C-cf"     'cxref-function-comment) ;; Control-C f
  18. (define-key c-mode-map "\C-cv"     'cxref-variable-comment) ;; Control-C v
  19. (define-key c-mode-map "\C-ce"     'cxref-endline-comment)  ;; Control-C e
  20. (define-key c-mode-map "\C-ci"     'cxref-inline-comment)   ;; Control-C i
  21.  
  22. ;; Insert a file comment suitable for parsing with cxref
  23.  
  24. (defun cxref-file-comment () "Inserts a file comment suitable for parsing with cxref" (interactive)
  25.   (let ((cp (make-marker)))
  26.  
  27.     (goto-char (point-min))
  28.  
  29.     (insert   "/***************************************") (c-indent-command)
  30.     (insert (concat "\n$" "Header" "$")) (c-indent-command)
  31.     (insert "\n")
  32.     (insert "\n")(c-indent-command)
  33.     (set-marker cp (point))
  34.     (insert "\n***************************************/") (c-indent-command)
  35.     (insert "\n\n\n")
  36.     (while (looking-at "\n") (delete-char 1))
  37.  
  38.     (if (string-match "\\.h$" (buffer-file-name))
  39.         (let ((st) (defname (file-name-nondirectory (buffer-file-name))))
  40.           (while (setq st (string-match "\\." defname))
  41.             (setq defname (concat (substring defname 0 st) "_" (substring defname (+ 1 st) nil))))
  42.           (setq defname (upcase defname))
  43.           (insert (concat "#ifndef " defname "\n"))
  44.           (insert (concat "#define " defname "    /*+ To stop multiple inclusions. +*/\n"))
  45.           (insert "\n")
  46.           (goto-char (point-max))
  47.           (while (looking-at-backward "\n") (delete-char -1))
  48.           (insert "\n\n")
  49.           (insert (concat "#endif /* " defname " */\n"))
  50.           ))
  51.  
  52.     (goto-char cp) (c-indent-command)
  53.     ))
  54.  
  55. ;; Insert a function comment suitable for parsing with cxref
  56.  
  57. (defun cxref-function-comment () "Inserts a function comment suitable for parsing with cxref" (interactive)
  58.   (let ((bp (make-marker)) (cp (make-marker)) (fp (make-marker)) (as) (ae) (a) (depth 0))
  59.  
  60.     (beginning-of-line)
  61.  
  62.     (while (looking-at-backward "\n\n") (delete-backward-char 1))
  63.  
  64.     (insert "\n\n")
  65.     (insert "/*++++++++++++++++++++++++++++++++++++++") (c-indent-command)
  66.     (insert "\n")
  67.     (set-marker bp (point))
  68.     (insert "\n")
  69.     (set-marker cp (point))
  70.     (insert "++++++++++++++++++++++++++++++++++++++*/") (c-indent-command)
  71.     (insert "\n\n")
  72.  
  73.     (if (looking-at "static") (re-search-forward "[ \t\n]+"))
  74.     (set-marker fp (point))
  75.  
  76.     (if (not (looking-at "void[\t ]+[a-zA-Z0-9_]"))
  77.         (progn
  78.           (setq as (point))
  79.           (search-forward "(") (backward-char)
  80.           (setq ae (point))
  81.           (setq a (buffer-substring as ae))
  82.           (goto-char cp)
  83.           (insert "\n")
  84.           (insert a) (c-indent-line)
  85.           (insert "\n")
  86.           (set-marker cp (point))
  87.           (goto-char fp)
  88.           )
  89.       )
  90.  
  91.     (search-forward "(") (set-marker fp (point))
  92.  
  93.     (catch 'finished-args
  94.  
  95.       (while t
  96.  
  97.         (if (looking-at-backward ")")
  98.             (throw 'finished-args t))
  99.  
  100.         (re-search-forward "[\n\t ]*")
  101.         (set-marker fp (point))
  102.         (setq as (point))
  103.  
  104.         (while (not (and (= depth 0) (looking-at "[,)]")))
  105.           (if (looking-at "[({]")
  106.               (setq depth (1+ depth)))
  107.           (if (looking-at "[)}]")
  108.               (setq depth (1- depth)))
  109.           (forward-char))
  110.  
  111.         (set-marker fp (1+ (point)))
  112.  
  113.         (re-search-backward "[\n\t ]*")
  114.         (setq ae (point))
  115.  
  116.         (setq a (buffer-substring as ae))
  117.  
  118.         (if (not (or (string= a "void") (string= a "")))
  119.             (progn
  120.               (goto-char cp)
  121.               (insert "\n")
  122.               (insert a) (c-indent-line)
  123.               (insert "\n")
  124.               (set-marker cp (point))
  125.               ))
  126.         (goto-char fp)
  127.         ))
  128.  
  129.     (goto-char bp) (c-indent-command)
  130.     ))
  131.  
  132. ;; Insert a variable comment suitable for parsing with cxref
  133.  
  134. (defun cxref-variable-comment () "Inserts a variable comment suitable for parsing with cxref" (interactive)
  135.   (let ((fp (make-marker)))
  136.     (beginning-of-line)
  137.  
  138.     (while (looking-at-backward "\n\n") (delete-backward-char 1))
  139.  
  140.     (insert "\n")
  141.     (insert "/*+ ")
  142.     (set-marker fp (point))
  143.     (insert " +*/")
  144.     (insert "\n")
  145.  
  146.     (goto-char fp) (c-indent-command)
  147.     ))
  148.  
  149. ;; Inserts an end of line comment that is parsed by cxref
  150.  
  151. (defun cxref-endline-comment () "Inserts an end of line comment that is parsed by cxref" (interactive)
  152.   (let ((fp (make-marker)))
  153.     (end-of-line)
  154.     (indent-to-column (c-comment-indent))
  155.  
  156.     (insert "/*+ ")
  157.     (setq fp (point))
  158.     (insert " +*/")
  159.  
  160.     (goto-char fp)
  161.     ))
  162.  
  163. ;; Insert an inline comment that is not parsed with cxref
  164.  
  165. (defun cxref-inline-comment () "Inserts an inline comment that is not parsed with cxref" (interactive)
  166.   (let ((fp (make-marker)))
  167.     (beginning-of-line)
  168.  
  169.     (while (looking-at-backward "\n\n") (delete-backward-char 1))
  170.  
  171.     (insert "\n")
  172.     (insert "/* ")
  173.     (set-marker fp (point))
  174.     (insert " */")
  175.     (insert "\n\n")
  176.  
  177.     (goto-char fp) (c-indent-command)
  178.     ))
  179.  
  180. ;;  A Very Useful Function
  181.  
  182. (defun looking-at-backward (arg)
  183.   (save-excursion
  184.     (let ((cp (point)) (return))
  185.       (if (re-search-backward arg (point-min) t)
  186.           (if (re-search-forward arg cp t)
  187.               (if (= (point) cp)
  188.                   (setq return t)
  189.                 )))
  190.       return
  191.       )))
  192.